import { BaseApiService } from '../base/api.service';
import type { ChartSeries, ChartConfig, ChartDataPoint } from '@/types/analysis/charts';
import type { MonthlyStats } from '@/types/analysis/statistics';

/**
 * 图表数据服务类
 */
export class ChartsService extends BaseApiService {
  constructor() {
    super('/api/gitlog/stats');
  }

  /**
   * 获取月度统计数据
   */
  async getMonthlyStats(): Promise<MonthlyStats[]> {
    return this.get<MonthlyStats[]>('monthly');
  }

  /**
   * 转换数据为图表格式
   */
  transformToChartData(data: ChartDataPoint[], xField: string, yField: string): ChartSeries {
    return {
      name: 'Data',
      data: data.map((item) => ({
        x: item[xField],
        y: item[yField],
      })),
    };
  }

  /**
   * 获取默认图表配置
   */
  getDefaultChartConfig(): ChartConfig {
    return {
      showLegend: true,
      height: 350,
    };
  }
}

// 导出单例实例
export const chartsService = new ChartsService();
